home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / prcgntn1.lha / Precognition / source / Interactor.c < prev    next >
C/C++ Source or Header  |  1992-12-23  |  7KB  |  343 lines

  1. /* ==========================================================================
  2. **
  3. **                   Interactor.c
  4. **
  5. ** ⌐1991 WILLISoft
  6. **
  7. ** ==========================================================================
  8. */
  9.  
  10. #include "Interactor.h"
  11. #include "InteractorClass.h"
  12. #include "pcgWindow.h"
  13.  
  14.  
  15. pcgWindow *Interactor_InteractorWindow( Interactor *self )
  16. {
  17.    return self->IaWindow;
  18. }
  19.  
  20.  
  21. void Interactor_SetInteractorWindow( Interactor *self, pcgWindow *window )
  22. {
  23.    self->IaWindow = window;
  24. }
  25.  
  26.  
  27. tPoint Interactor_Location( Interactor *self )
  28. {
  29.    return self->Location;
  30. }
  31.  
  32. tPoint Interactor_Size( Interactor *self )
  33. {
  34.    return self->Size;
  35. }
  36.  
  37. tPoint Interactor_SetLocation( Interactor  *self,
  38.                                PIXELS      LeftEdge,
  39.                                PIXELS      TopEdge )
  40. {
  41.    self->Location.x = LeftEdge;
  42.    self->Location.y = TopEdge;
  43.  
  44.    return self->Location;
  45. }
  46.  
  47. tPoint Interactor_SetSize( Interactor  *self,
  48.                            PIXELS      Width,
  49.                            PIXELS      Height )
  50. {
  51.    self->Size = AskSize( self, Width, Height );
  52.    return self->Size;
  53. }
  54.  
  55. pcgWindow *InteractorWindow( Interactor *self )
  56. {
  57.    struct InteractorClass *class;
  58.  
  59.  
  60.    if (class = (struct InteractorClass *) self->isa)
  61.    {
  62.       if (class->InteractorWindow)
  63.          return (*class->InteractorWindow)( self );
  64.    }
  65.    else
  66.       return NULL;
  67. }
  68.  
  69.  
  70. void SetInteractorWindow( Interactor *self, pcgWindow *window )
  71. {
  72.    struct InteractorClass *class;
  73.  
  74.  
  75.    if (class = (struct InteractorClass *) self->isa)
  76.    {
  77.       if (class->SetInteractorWindow)
  78.          (*class->SetInteractorWindow)( self, window );
  79.    }
  80. }
  81.  
  82.  
  83.  
  84. Gadget *FirstGadget( Interactor *self )
  85. {
  86.    struct InteractorClass *class;
  87.  
  88.  
  89.    if (class = (struct InteractorClass *) self->isa)
  90.    {
  91.       if (class->FirstGadget)
  92.          return (*class->FirstGadget)( self );
  93.    }
  94.    else
  95.       return NULL;
  96. }
  97.  
  98.  
  99. USHORT nGadgets( Interactor *self )
  100. {
  101.    struct InteractorClass *class;
  102.  
  103.  
  104.    if (class = (struct InteractorClass *) self->isa)
  105.    {
  106.       if (class->nGadgets)
  107.          return (*class->nGadgets)( self );
  108.    }
  109.    else
  110.       return 0;
  111. }
  112.  
  113.  
  114. ULONG IDCMPFlags( Interactor *self )
  115. {
  116.    ULONG flags = 0;
  117.    struct InteractorClass *class;
  118.  
  119.  
  120.    if (class = (struct InteractorClass *) self->isa)
  121.    {
  122.       if (class->IDCMPFlags)
  123.          flags = (*class->IDCMPFlags)( self );
  124.    }
  125.    return flags;
  126. }
  127.  
  128.  
  129.  
  130. USHORT ClaimEvent( Interactor    *self,
  131.                    IntuiMessage *event )
  132. {
  133.    USHORT claimed = 0;
  134.    struct InteractorClass *class;
  135.  
  136.  
  137.    if (class = (struct InteractorClass *) self->isa)
  138.    {
  139.       if (class->ClaimEvent)
  140.          claimed = (*class->ClaimEvent)( self, event );
  141.    }
  142.    return claimed;
  143. }
  144.  
  145.  
  146. USHORT Respond( Interactor    *self,
  147.                 IntuiMessage *event )
  148. {
  149.    USHORT response = 0;
  150.    struct InteractorClass *class;
  151.  
  152.  
  153.    if (class = (struct InteractorClass *) self->isa)
  154.    {
  155.       if (class->Respond)
  156.          response = (*class->Respond)( self, event );
  157.    }
  158.    return response;
  159.  
  160. }
  161.  
  162. void Refresh( Interactor  *self )
  163. {
  164.    struct InteractorClass *class;
  165.  
  166.    if (class = (struct InteractorClass *) self->isa)
  167.    {
  168.       if (class->Refresh)
  169.          (*class->Refresh)( self );
  170.    }
  171.  
  172. }
  173.  
  174.  
  175. BOOL EnableIactor( Interactor *self,
  176.              BOOL       enable )
  177. {
  178.    BOOL enabled = 0;
  179.    struct InteractorClass *class;
  180.  
  181.  
  182.    if (class = (struct InteractorClass *) self->isa)
  183.    {
  184.       if (class->EnableIactor)
  185.          enabled = (*class->EnableIactor)( self, enable );
  186.    }
  187.    return enabled;
  188.  
  189. }
  190.  
  191.  
  192. BOOL isEnabled( Interactor *self  )
  193. {
  194.    BOOL enabled = 0;
  195.    struct InteractorClass *class;
  196.  
  197.  
  198.    if (class = (struct InteractorClass *) self->isa)
  199.    {
  200.       if (class->isEnabled)
  201.          enabled = (*class->isEnabled)( self );
  202.    }
  203.    return enabled;
  204.  
  205. }
  206.  
  207.  
  208.  
  209. BOOL Activate( Interactor *self,
  210.                BOOL       activate )
  211. {
  212.    BOOL active = 0;
  213.    struct InteractorClass *class;
  214.  
  215.  
  216.    if (class = (struct InteractorClass *) self->isa)
  217.    {
  218.       if (class->Activate)
  219.          active = (*class->Activate)( self, activate );
  220.    }
  221.    return active;
  222.  
  223. }
  224.  
  225.  
  226. BOOL isActive( Interactor *self )
  227. {
  228.    BOOL active = 0;
  229.    struct InteractorClass *class;
  230.  
  231.    if (class = (struct InteractorClass *) self->isa)
  232.    {
  233.       if (class->isActive)
  234.          active = (*class->isActive)( self );
  235.    }
  236.    return active;
  237. }
  238.  
  239.  
  240. void Interactor_Refresh( Interactor *self )
  241. {
  242.    pcgWindow *window;
  243.  
  244.    /* If the subclasses have not redefined this, then simply
  245.     * render it.
  246.     */
  247.  
  248.    if (window = InteractorWindow(self))
  249.    {
  250.       Render( self, window->Window->RPort );
  251.    }
  252. }
  253.  
  254. void Interactor_CleanUp( Interactor *self )
  255. {
  256.    pcgWindow *w = InteractorWindow(self);
  257.    
  258.    if (w)
  259.    {
  260.       RemoveWindowPObject( w, self );
  261.    }
  262. }
  263.  
  264.  
  265. BOOL Interactor_elaborated = FALSE;
  266.  
  267. struct InteractorClass Interactor_Class;
  268.  
  269. void InteractorClass_Init( struct InteractorClass *class )
  270. {
  271.    GraphicObjectClass_Init( (struct GraphicObjectClass *) class );
  272.    class->isa                 = GraphicObjectClass();
  273.    class->ClassName           = "Interactor";
  274.    class->CleanUp             = Interactor_CleanUp;
  275.  
  276.    class->Location            = Interactor_Location;
  277.    class->SetLocation         = Interactor_SetLocation;
  278.    class->Size                = Interactor_Size;
  279.    /* class->AskSize = NULL;*/
  280.    class->SetSize             = Interactor_SetSize;
  281.    /*class->SizeFlags          = GraphicObject_SizeFlagsAll;*/
  282. /*   class->Render              = NULL;*/
  283.    class->InteractorWindow     = Interactor_InteractorWindow;
  284.    class->SetInteractorWindow  = Interactor_SetInteractorWindow;
  285. /*   class->FirstGadget         = NULL;*/
  286. /*   class->nGadgets            = NULL;*/
  287. /*   class->IDCMPFlags          = NULL;*/
  288. /*   class->ClaimEvent          = NULL;*/
  289. /*   class->Respond             = NULL;*/
  290.    class->Refresh             = Interactor_Refresh;
  291. /*   class->EnableIactor              = NULL;*/
  292. /*   class->isEnabled           = NULL;*/
  293. /*   class->Activate            = NULL;*/
  294. /*   class->isActive            = NULL;*/
  295. }
  296.  
  297.  
  298. struct InteractorClass *InteractorClass( void )
  299. {
  300.    if (! Interactor_elaborated)
  301.    {
  302.       InteractorClass_Init( &Interactor_Class );
  303.       Interactor_elaborated = TRUE;
  304.    }
  305.  
  306.    return &Interactor_Class;
  307. }
  308.  
  309.  
  310. void Interactor_Init( Interactor *self )
  311. {
  312.    GraphicObject_Init( self );
  313.    self->isa             = InteractorClass();
  314.    self->IaWindow        = NULL;
  315.    self->Location.x      = 0;
  316.    self->Location.y      = 0;
  317.    self->Size.x          = 0;
  318.    self->Size.y          = 0;
  319. }
  320.  
  321.  
  322. BOOL ActivateNext( Interactor *self )
  323. {
  324.    Interactor *iactor;
  325.    pcgWindow  *pwindow;
  326.  
  327.    for (iactor=self->Next; iactor!=NULL; iactor=iactor->Next)
  328.       if (Activate(iactor, TRUE)) return TRUE;
  329.  
  330.    /* couldn't find an activatable interactor.  Try from start of chain. */
  331.    pwindow = InteractorWindow(self);
  332.    if (pwindow)
  333.    {
  334.       for (iactor=pwindow->FirstInteractor; iactor!=self; iactor=iactor->Next)
  335.          if (Activate(iactor, TRUE)) return TRUE;
  336.  
  337.  
  338.    }
  339.  
  340.    return Activate(self, TRUE); /* reactivate the same interactor. */
  341. }
  342.  
  343.